﻿using lingopen;
using lingopen.Application;
using lingopen.Application.System;
using lingopen.Entity.System;
using lingopen.Jabil.Server.Areas;
using lingopen.Jabil.Server.Core;
using Microsoft.AspNetCore.Mvc;

namespace lingopen.Jabil.Server.Areas.SystemManage.Controllers
{
    [Area(AreaNames.SystemManage)]
    [LoginAuthorizeAttribute]
    public class ConfigController : WebController
    {
        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="pagination">页码</param>
        /// <param name="keyword">关键字</param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult GetModels(Pagination pagination, string keyword)
        {
            PagedData<Sys_Config> data = this.CreateService<IConfigAppService>().GetConfigs(pagination, keyword);
            return this.UISuccessData(data);
        }

        [HttpPost]
        //[ValidateAntiForgeryToken]
        public ActionResult Add(AddConfigInput input)
        {
            input.CreateUserId = this.CurrentSession.UserId;
            this.CreateService<IEntityAppService>().AddFromDto<Sys_Config, AddConfigInput>(input);
            return this.UISuccessData();
        }
        [HttpPost]
        //[ValidateAntiForgeryToken]
        public ActionResult Update(UpdateConfigInput input)
        {
            this.CreateService<IEntityAppService>().UpdateFromDto<Sys_Config, UpdateConfigInput>(input);
            return this.UISuccessData();
        }

        [HttpPost]
        //[ValidateAntiForgeryToken]
        public ActionResult Delete(string id)
        {
            this.CreateService<IEntityAppService>().SoftDelete<Sys_Config>(id, this.CurrentSession.UserId);
            return this.UISuccessData();
        }
        [HttpGet]
        [SkipLoginAuthorize]
        public ActionResult GetSystemInfo()
        {
            //    var data = this.CreateService<IConfigAppService>().GetConfig("0000");
            //    var obj = data.Description.FromJson<dynamic>();
            return UISuccessData(null);
        }
    }

}